# -*- coding: utf-8 -*-
'''
Created on Jul 22, 2019

@author: yl
'''

import cv2
import matplotlib.pyplot as plt
from scipy import signal
from FFT_Interpolation import FFT_interpolation_boxcar, FFT_interpolation_2, FFT_interpolation_compare, FFT_cal
import numpy as np

img_set = []
pix_size = 5.3e-6
pattern_path = r'C:\Users\yu03\Desktop\Spot_&_Noise\Ref_Spot_50fps_80usExpos.avi'

cap = cv2.VideoCapture(pattern_path)
frame_num = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
print(frame_num, "Frames")
# while(cap.isOpened()):
for k in range(frame_num):
    ret, frame = cap.read() 
    img = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    img_set.append(img)
    line = np.arange(1280)
    points = np.vstack((line,img[512]*(-1)+1000)).astype(np.int32).T
    cv2.polylines(img, [points], isClosed=False, color=(255,255,255))
    cv2.imshow('frame',img)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break
cap.release()
cv2.destroyAllWindows()


# img = img_set[0]
# print(len(img))

plt.figure(1)
im = plt.imshow(img_set[0], cmap='gray')
plt.colorbar(im, fraction=0.046, pad=0.04)
plt.figure(2)
for img in img_set[:1]:
    plt.plot(img[512])
plt.grid(which='both', axis='both')
plt.show()
    
    
    
    